package daoImpl;


import dao.*;
import util.DatabaseUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class LoginDaoImpl extends BaseDao implements LoginDao {

    public LoginDaoImpl(Connection conn) {
        super(conn);
    }

    @Override
    public int doLogin(String name, String pwd) {
        PreparedStatement ps = null;
       int num=0;
        String sql ="SELECT count(1) FROM easybuy_user WHERE loginName=? and password=?";
        System.out.println("----"+pwd);
        try {
            ps = conn.prepareStatement(sql);
            ps.setObject(1, name);
            ps.setObject(2, pwd);

            rs = ps.executeQuery();
        if(rs.next()){
            num=rs.getInt(1);
        }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.closeAll(null, ps, rs);
        }
        return num;
    }
}
